$(document).ready(function() {
	$("#contact_form").validate({
		rules: {
	        name: {
	          required: true
	        },
	        email: {
	          required: true,
	          email:true
	        },
	        message: {
	          required: true
	        }
		}
	});
	
     $('#btn-send').click(function(){
    	 if ($("#contact_form").valid()){
	        $.ajax({
	            url: settings.base_url + 'index.php/' + lang.lang_key + '/contact/send_form/',
	            dataType: 'json',
	            type: 'POST',
	            data: {
	                nume: $('#name').val(),
	                email: $('#email').val(),
	                mesaj: $('#message').val(),
	                phone: $('#phone').val(),
	                contact_by: $('input[name="contact_by"]').val(),
	                contact_time: $('#contact_time').val()
	            },
	            success: function(data){
	                $("#contact_form").hide();
	                if (data.status == '1')
	                    $('#confirm').show();
	                else
	                    $('#error').show();
	
	            },
	            complete: function()
	            {
	            },
	            error: function()
	            {
	                $("#contact_form").hide();
	                $('#error').show();
	            }
	        });
    	 }
    });
     
     var email_contact = '[email_contact]';
 	if (lang.email_contact != 'undefined'){
 		email_contact = lang.email_contact;
 	}
 	
 	$("#email").focus(function(){
 		if ($(this).val() == email_contact){
 			$(this).val('');
 		}
 	});
 	$("#email").blur(function(){
 		if ($(this).val() == ''){
 			$(this).val(email_contact);
 		}
 	});
 	
 	var your_name = '[your_name]';
 	if (lang.your_name != 'undefined'){
 		your_name = lang.your_name;
 	}
 	
 	$("#name").focus(function(){
 		if ($(this).val() == your_name){
 			$(this).val('');
 		}
 	});
 	$("#name").blur(function(){
 		if ($(this).val() == ''){
 			$(this).val(your_name);
 		}
 	});
 		
 	var phone_contact = '[phone_contact]';
 	if (typeof lang.phone_contact != 'undefined'){
 		phone_contact = lang.phone_contact;
 	}
 	
 	$("#phone").focus(function(){
 		if ($(this).val() == phone_contact){
 			$(this).val('');
 		}
 	});
 	$("#phone").blur(function(){
 		if ($(this).val() == ''){
 			$(this).val(phone_contact);
 		}
 	});
 	
 	$("#contact_form_selec_label").click(function(){
 		$("#contact-time-container").css('opacity','1');
 	});
 	$("#contact_time").change(function(){
 		$("#contact-time-container").css('opacity','0');
 		$("#contact_form_selec_label").html($("#contact_time").val());
 	});
 	
 	$("#contact_time").trigger("change");
});

function setConactTime(el){
	$("#contact_time").val($(el).html());
	$("#contact_time").trigger("change");
}